package com.example.administrator.officeplatform.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.officeplatform.R;
import com.example.administrator.officeplatform.bean.CostInfo;
import com.example.administrator.officeplatform.bean.ReimbursementVoInfo;
import com.example.administrator.officeplatform.utils.DateUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/12/21.
 */

public class YCBPeopleAdatper extends RecyclerView.Adapter{
    public static interface OnRecyclerViewListener {
        void onItemClick(int position);

        boolean onItemLongClick(int position);
    }

    private YCBPeopleAdatper.OnRecyclerViewListener onRecyclerViewListener;

    public void setOnRecyclerViewListener(YCBPeopleAdatper.OnRecyclerViewListener onRecyclerViewListener) {
        this.onRecyclerViewListener = onRecyclerViewListener;
    }

    private List<CostInfo> list = new ArrayList<>();
    private Context mContext;

    public YCBPeopleAdatper(List<CostInfo> list, Context mContext) {
        this.list = list;
        this.mContext=mContext;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_loan, null);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(lp);
        return new PersonViewHolder(view);    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final PersonViewHolder personViewHolder = (PersonViewHolder) holder;
        personViewHolder.position = position;
        CostInfo bmInfo = list.get(position);
        if (bmInfo.getCategoryName() == null){

        }else {
            personViewHolder.tv_allmoney.setText("类别："+bmInfo.getCategoryName());

        }
        if (bmInfo.getSettlementCycle() == null){

        }else {
            try {
                String time  = DateUtil.changeDate(bmInfo.getSettlementCycle().toString());
                personViewHolder.tv_money.setText("结算归属周期："+time);

            } catch (Exception e) {
                e.printStackTrace();
            }

        }
        if (bmInfo.getSupplierName() == null){

        }else {
            personViewHolder.tv_time.setText("供应商/员工名称："+bmInfo.getSupplierName().toString());

        }
        if (bmInfo.getReimbursementCode() == null){

        }else {
            personViewHolder.tv_name.setText("单号："+bmInfo.getReimbursementCode().toString());

        }
//        personViewHolder.tv_money.setText(bmInfo.getLoanSurplusMoney().toString());

    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    class PersonViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
        public View rootView;
        public int position;
        public TextView tv_name,tv_time,tv_allmoney,tv_money;
        public PersonViewHolder(View itemView) {
            super(itemView);
            tv_name = (TextView)itemView.findViewById(R.id.tv_name);
            tv_time = (TextView)itemView.findViewById(R.id.tv_time);
            tv_allmoney = (TextView)itemView.findViewById(R.id.tv_allmoney);
            tv_money = (TextView)itemView.findViewById(R.id.tv_money);
            rootView = itemView.findViewById(R.id.ll);
            rootView.setOnClickListener(this);
            rootView.setOnLongClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (null != onRecyclerViewListener) {
                onRecyclerViewListener.onItemClick(position);
            }
        }

        @Override
        public boolean onLongClick(View v) {
            if (null != onRecyclerViewListener) {
                return onRecyclerViewListener.onItemLongClick(position);
            }
            return false;
        }
    }
}